import 'package:flutter/material.dart';
import 'package:share/share.dart';
import 'data.dart';
import '../../widgets/common_title.dart';
import '../../widgets/common_swipper.dart';
import '../../widgets/common_tag.dart';
import '../../widgets/room_appliance.dart';
import '../../pages/home/info/index.dart';

var bottomBtnStyle = TextStyle(
  color: Colors.white,
  fontSize: 24.0
);

class RoomDetailPage extends StatefulWidget {
  final String roomId;

  const RoomDetailPage({Key key, this.roomId}) : super(key: key);

  @override
  _RoomDetailPageState createState() => _RoomDetailPageState();
}

class _RoomDetailPageState extends State<RoomDetailPage> {
  RoomDetailData data;
  bool isLike = false;
  bool showAllText = false;

  @override
  void initState() {
    setState(() {
      data = defaultData;
    });
    super.initState();
  }
  

  @override
  Widget build(BuildContext context) {
    if (null == data) return Container();

    var showTextTool = data.subTitle.length > 100;

    return Scaffold(
      appBar: AppBar(
        title: Text(data.title),
        actions: [
          IconButton(
            onPressed: (){
              Share.share('https://baidu.com');
            }, 
            icon: Icon(Icons.share)
          )
        ],
      ),
      body: Stack(
        children: [
          ListView(
            children: [
              CommonSwipper(images: data.houseImgs),
              CommonTitle(data.title),
              Container(
                padding: EdgeInsets.only(left: 10.0),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    Text(data.price.toString(), style: TextStyle(
                      color: Colors.pink,
                      fontSize: 20.0
                    ),),
                    Text('元/月（押一付三）', style: TextStyle(
                      color: Colors.pink,
                      fontSize: 14.0
                    ),)
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 10.0, top: 6.0),
                child: Wrap(
                  spacing: 5.0,
                  children: data.tags.map((e) => CommonTag(e)).toList(),
                ),
              ),
              Divider(
                color: Colors.grey,
                indent: 10.0,
                endIndent: 10.0,
              ),
              Container(
                padding: EdgeInsets.only(left: 10.0, top: 6.0),
                child: Wrap(
                  runSpacing: 10.0,
                  children: [
                    baseInfoItem("面积：${data.size}平方"),
                    baseInfoItem("楼层：${data.floor}平方"),
                    baseInfoItem("房型：${data.roomType}平方"),
                    baseInfoItem("装修：精装"),
                  ],
                ),
              ),
              CommonTitle("房屋配置"),
              RoomApplianceList(list: data.applicances),
              CommonTitle("房屋概况"),
              Container(
                padding: EdgeInsets.only(left: 10.0, right: 10.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(data.subTitle??'暂无概况',
                      maxLines: showAllText ? null : 5,
                    ),
                    showTextTool ? Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        GestureDetector(
                          onTap: (){
                            setState(() {
                              showAllText = !showAllText;
                            });
                          },
                          child: Row(
                            children: [
                              Text(showAllText ? '收起' : '展开'),
                              Icon(showAllText ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down)
                            ],
                          ),
                        ),
                        Text('举报')
                      ],
                    ) : Container()
                  ],
                ),
              ),
              CommonTitle("猜你喜欢"),
              Info(),
              Container(
                height: 100.0,
              )
            ],
          ),
          Positioned(
            width: MediaQuery.of(context).size.width,
            height: 100,
            bottom: 0,
            child: Container(
              padding: EdgeInsets.only(left: 10.0, top: 20, right: 20.0, bottom: 20.0),
              color: Colors.grey[200],
              child: Row(
                children: [
                  GestureDetector(
                    onTap: (){
                      setState(() {
                        isLike = !isLike;
                      });
                    },
                    child: Container(
                      width: 50.0,
                      height: 45.0,
                      margin: EdgeInsets.only(right: 10.0),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Icon(isLike ? Icons.star : Icons.star_border, color: isLike ? Colors.green : Colors.black, size: 24.0,),
                          Text(isLike ? '已收藏' : '收藏', style: TextStyle(fontSize: 12.0),)
                        ],
                      ),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      height: 45.0,
                      margin: EdgeInsets.only(right: 5.0),
                      decoration: BoxDecoration(
                        color: Colors.cyan,
                        borderRadius: BorderRadius.circular(10.0)
                      ),
                      child: Center(
                        child: Text('联系房东', style: bottomBtnStyle,),
                      ),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      height: 45.0,
                      decoration: BoxDecoration(
                        color: Colors.green,
                        borderRadius: BorderRadius.circular(10.0)
                      ),
                      child: Center(
                        child: Text('预约看房', style: bottomBtnStyle,),
                      ),
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}

class baseInfoItem extends StatelessWidget {
  final String content;

  const baseInfoItem(this.content, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: (MediaQuery.of(context).size.width - 3*10.0) / 2,
      child: Text(content, style: TextStyle(
        fontSize: 14.0
      ),),
    );
  }
}